﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.WS.UserControls;
using GCELibrary.Current;
using System.Transactions;
using ZF.BLL;
using Newtonsoft.Json;
using ZF.BLL.Admin;
using ZF.WS.Admin.service;
using ZF.BLL.ServiceModel;
namespace ZF.WS.Admin
{

    public partial class smsgManage : smsg 
    {
    

        [PageArgument(Key = "id", CanNull = false)]
        public int  Id { get; set; }
        public Model.Sys_Service Service { get; set; }
        public SMSG Model { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                
                
                    Edit();
            }
        }
        public void InitControls()
        {

     
     
        }

 

        public void Edit()
        {
            using (var dc = BLL.SiteInfo.CreateDBDataContext())
            {
                var service = dc.Sys_Service.FirstOrDefault(p => p.ServiceId == Id);
                if (service == null)
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                InitControls();
                this.Service = service;
                this.Model = (SMSG)GetJsonObj(service.Json);
            }
        }
        public object GetJsonObj(string json)
        {
            SMSG result = null;
            try
            {
                result = Newtonsoft.Json.JsonConvert.DeserializeObject<SMSG>(json);
            }
            catch (Exception ex)
            {
                result = new SMSG();
            }
            return result;
        }
        public void EditSubmit(object sender, EventArgs e)
        {

          
                using (var dc = BLL.SiteInfo.CreateDBDataContext())
                {
                    var service = dc.Sys_Service.FirstOrDefault(p => p.ServiceId == Id);
                    if (service == null)
                        throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                    service.IsAcc = true;
                    dc.SubmitChanges();
                    WarnFactory.CreateWarn(new PageWarnParameter()
                    {
                        JscriptMode = true,
                        Message = "确认成功",
                        Link = WarnLink.Current,
                    }).Alert();

                }

 
        }

    
    }
 
}
